package com.gientech.user.register.controller;

import com.gientech.user.register.entity.Developer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 开发者注册服务-控制器
 * @ClassName: DeveloperRegisterController
 * @Author: luowenbin
 * @Version: 1.0
 */
@RestController()
@CrossOrigin(origins = "*")
public class DeveloperRegisterController {

    final static String DATAKEY = "developerReq";

    @Autowired
    RedisTemplate redisTemplate;


    /**
     * 此处使用Redis list代替DB存储 实现注册
     * @param developer
     * @return
     */
    @PostMapping("/developer/register")
    @Transactional
    public String developerRegiest(@RequestBody Developer developer) {
        System.out.println("开发者注册信息：" + developer.toString());
        // 存储到redis list里面
        redisTemplate.opsForList().rightPush(DATAKEY, developer);
        return "注册成功";
    }

    //获取所有用户注册信息
    @GetMapping("/getDevelopers")
    public Object getDevelopers() {
        //从redis获取用户信息list
        List range = redisTemplate.opsForList().range(DATAKEY, 0, -1);
        System.out.println(range);
        //返回用户List
        return range;
    }
}
